//
//  TitleInfoView.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2020/2/10.
//  Copyright © 2020 zwb. All rights reserved.
//

import UIKit

class TitleInfoView: UIView {
    
    @IBOutlet weak var statusBtn: StatusButton!
    @IBOutlet weak var addr: UITextField!
    
    @IBOutlet weak var titleLab: UILabel!
    
}
enum StatusBtnStyle {// 边框 ，  填充 ，  圆形边框
    case border,fill,roundBorder
}

class StatusButton: UIButton {
    //    0:未提交;1:审核中;2:未开始;3:进行中;4:已中标;5:已流标
    
    override func awakeFromNib() {
        
        configUI()
    }
    
    func configUI() {
        self.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        self.layer.cornerRadius = 3
        self.layer.masksToBounds = true
        
//        let cover = UIView()
//        cover.backgroundColor = .white
//        self.addSubview(cover)
//        cover.snp.makeConstraints { make in
//            make.left.right.top.equalToSuperview()
//            make.width.equalTo(8)
//        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        configUI()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
 
    
    func setBtnStyle(style:StatusBtnStyle,color:UIColor) {
        switch style {
        case .border:
             self.backgroundColor = .clear
              self.layer.borderWidth = 1
              self.layer.borderColor = color.cgColor
              self.layer.cornerRadius = 3
              self.setTitleColor(color, for: .normal)
        case .fill:
            self.setTitleColor(.white, for: .normal)
            self.backgroundColor = color
            self.layer.cornerRadius = 3
        case .roundBorder:
            self.backgroundColor = .clear
           self.layer.borderWidth = 1
           self.layer.borderColor = color.cgColor
           self.layer.cornerRadius = 10
           self.setTitleColor(color, for: .normal)
            
         
        }
    }
    func setBtnStyle(color:UIColor) {
     
            self.backgroundColor = color
           
        self.layer.masksToBounds = true
        self.setTitleColor(.white, for: .normal)
       
        self.layer.borderWidth = 0
        self.layer.cornerRadius = CGFloat(zbListStatusHeight/2)
    }
    
    
    
    @discardableResult
    func setZBJPStatus(listType:TBandJPType,auditmark:Int,status:Int,tbType:ZTBInnerType) -> String {
        
        self.setTitleColor(.white, for: .normal)
        
        var btnName = ""
        if tbType == .tbMytbKHW {
            if status == 1 {
                btnName =  "已开标"
                self.setBtnStyle(color: .red)
            } else if status == 0 {
                btnName =  "未中标"
                self.setBtnStyle(color: .lightGray)
            } else {
                btnName =  "已放弃"
            }
        } else if tbType == .tbRecordKHW {
            if status == 1 {
                btnName =  "已中标"
                self.setBtnStyle(color: .red)
            } else if status == 0 {
                btnName =  "未中标"
                self.setBtnStyle(color: .lightGray)
            } else {
                btnName =  "已放弃"
                self.setBtnStyle(color: .lightGray)
            }
        } else if tbType == .chujiaRecordKHW {
                   if status == 1 {
                       btnName =  "已成交"
                       self.setBtnStyle(color: UIColor(kshex: tenderGreen))

                   } else if status == 0 {
                       btnName =  "未成交"
                       self.setBtnStyle(color: UIColor.lightGray)
                   } else if status == 2 {
                       btnName =  "已弃标"
                       self.setBtnStyle(color: UIColor(kshex: "dbdbdb"))
                       self.setTitleColor(.black, for: .normal)
                   } else {
                       btnName =  "已结束"
                       self.setBtnStyle(color: UIColor.lightGray)
                   }
        } else if tbType == .zbAnnouncementKHW {
            btnName = "已开标"
            self.setBtnStyle(color: .red)
        } else if tbType == .chujiaRecordJP {
            btnName = "已出价"
        } else if tbType == .cjAnnouncementKHW {
            btnName = "已开拍"
            self.setBtnStyle(color: UIColor(kshex: tenderGreen))
        } else {
            if auditmark == 1 {
                switch status {
                case 0:
                    btnName = "未开始"
                    self.setBtnStyle(color: UIColor(kshex: tenderBlue))
                case 1:
                    btnName = listType == .TB ? "已开标" : "已成交"
                    self.setBtnStyle(color: UIColor(kshex: tenderGreen))
                case 2:
                    btnName = "进行中"
                    self.setBtnStyle(color: .red)

                case 3:
                    btnName = "已结束"
                    self.setBtnStyle(color: UIColor.lightGray)
                case 4:
                    btnName = listType == .TB ? "已流标" : "已流拍"
                    self.setBtnStyle(color: UIColor.lightGray)
                default:
                    print("33")
                }
            } else if auditmark == 0 {
                btnName = "未提交"
                self.setBtnStyle(color: UIColor(kshex: tenderBlue))
            } else if auditmark == 2 {
                btnName = "已退回"
                self.setBtnStyle(color: UIColor.lightGray)
            } else if auditmark == 9 {
                btnName = "已提交"
                self.setBtnStyle(color: UIColor(kshex: tenderGreen))
            }
        }
        self.setTitle(btnName, for: .normal)
        return btnName
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        self.titleLabel?.frame = CGRect(x: 10, y: 0, width: self.ks_width - 10, height: self.ks_height)
    }
}
 
